package com.example.wsljh12138;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
@WebServlet(name = "ListCakeServlet",urlPatterns = "/ListCakeServlet")
public class ListCakeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset = utf-8");
        PrintWriter out = response.getWriter();
        Collection<Cake>cakes = CakeDB.getAll();
        out.write("本站提供的蛋糕有：<br>");
        for (Cake cake : cakes){
            String url = "PurchaseServlet?id=" + cake.getId();
            out.write(cake.getName() + "<a href='"+url+"'>点击购买</a><br>");
        }
    }



}
